package cn.test.servlet;


import java.io.File;
import java.io.FileFilter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class DeleteFileServlet extends HttpServlet {

	public DeleteFileServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); 
	}
	public void init() throws ServletException {
		File file=new File(".");
		//first solution
//		File[] subFiles=file.listFiles();
//		for(File f:subFiles){
//			if(f.getName().endsWith("xls")){
//				f.delete();
//			}
//		}
		//second solution
		File[] subFiles=file.listFiles(new FileFilter(){
			@Override
			public boolean accept(File pathname) {
				if(pathname.getName().endsWith("xls")){
					return true;
				}
				return false;
			}
		});
		for(File f:subFiles){
			f.delete();
		}
	}

}
